package Demo;

import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        Thread t=new Thread(()->{
            //不可以写成t.isInterrupted()
            while(!Thread.currentThread().isInterrupted()) {
                System.out.println("hello thread");
                /*try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }*/
            }
            System.out.println("线程终止");
        });
        t.start();
        System.out.println("请输入任意内容以终止线程t:");
        Scanner sc=new Scanner(System.in);
        sc.next();
        t.interrupt();
    }
}
